package com.bwie.controller;

import com.bwie.pojo.TbType;
import com.bwie.service.TbTypeService;
import com.bwie.utils.Result;
import com.bwie.vo.PageInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 军哥
 * @version 1.0
 * @description: TODO
 * @date 2025/5/24 9:03
 */

@RestController
@RequestMapping("/shop/type")
public class TbTypeController {

    @Autowired
    TbTypeService tbTypeService;

    /**
     * @description 添加产品分类
     * @params [tbType]
     * @return com.bwie.utils.Result
     * @author 军哥
     * @date 2025/5/24 9:05
     */
    @PostMapping
    public Result addType(@RequestBody TbType tbType) {
        return tbTypeService.addType(tbType);
    }

    /**
     * @description 根据ID删除商品分类
     * @params [typeId]
     * @return com.bwie.utils.Result
     * @author 军哥
     * @date 2025/5/24 9:15
     */
    @DeleteMapping("/deleteType/{typeId}")
    public Result deleteType(@PathVariable("typeId") Integer typeId) {
        return tbTypeService.deleteType(typeId);
    }

    /**
     * @description 获取商品类型的树（用户表格）
     * @params [pageInfoVo]
     * @return com.bwie.utils.Result
     * @author 军哥
     * @date 2025/5/24 9:20
     */
    @GetMapping
    public Result getTypeTree() {
        return tbTypeService.getTypeTree();
    }

    /**
     * @description 获取商品类型的树（用于下拉框）
     * @params [pageInfoVo]
     * @return com.bwie.utils.Result
     * @author 军哥
     * @date 2025/5/24 9:20
     */
    @PostMapping("/getTypeSelectTree")
    public Result getTypeSelectTree() {
        return tbTypeService.getTypeSelectTree();
    }

    /**
     * @description 显示或者隐藏类型
     * @params [typeId, typeStatus]
     * @return com.bwie.utils.Result
     * @author 军哥
     * @date 2025/5/26 14:07
     */
    @PostMapping("/setTypeStatus/{typeId}/{typeStatus}")
    public Result setTypeStatus(@PathVariable("typeId") Integer typeId, @PathVariable("typeStatus") Integer typeStatus) {
        return tbTypeService.setTypeStatus(typeId, typeStatus);
    }

    /**
     * @description 删除分类
     * @params [typeId]
     * @return com.bwie.utils.Result
     * @author 军哥
     * @date 2025/5/26 14:11
     */
    @PostMapping(("/deleteTypeById/{typeId}"))
    public Result deleteTypeById(@PathVariable("typeId") Integer typeId) {
        return tbTypeService.deleteTypeById(typeId);
    }

    /**
     * @description 产品类型图片上传
     * @params [file]
     * @return com.bwie.utils.Result
     * @author 军哥
     * @date 2025/5/26 14:59
     */
    @PostMapping("/uploadFile")
    public Result uploadFile(@RequestPart("file") MultipartFile file) {
        return tbTypeService.uploadFile(file);
    }

    /**
     * @description 修改商品类型信息
     * @params [tbType]
     * @return com.bwie.utils.Result
     * @author 军哥
     * @date 2025/5/26 15:49
     */
    @PostMapping("/updateType")
    public Result updateType(@RequestBody TbType tbType) {
        return tbTypeService.updateType(tbType);
    }

}
